﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FlubuCore.BuildServers.Configurations.Models.Jenkins
{
    public class JenkinsOptionsDirective
    {
        /// <summary>
        /// Persist artifacts and console output for the specific number of recent Pipeline runs.
        /// For example: options { buildDiscarder(logRotator(numToKeepStr: '1')) }
        /// </summary>
        public int? BuildDiscarder { get; set; }

        /// <summary>
        /// Perform the automatic source control checkout in a subdirectory of the workspace.
        /// For example: options { checkoutToSubdirectory('foo')
        /// </summary>
        public string CheckoutToSubDirectory { get; set; }

        /// <summary>
        /// Disallow concurrent executions of the Pipeline. Can be useful for preventing simultaneous accesses to shared resources, etc.
        /// For example: options { disableConcurrentBuilds() }
        /// </summary>
        public bool DisableConcurrentBuilds { get; set; } = true;

        /// <summary>
        /// Do not allow the pipeline to resume if the master restarts.
        /// For example: options { disableResume() }
        /// </summary>
        public bool DisableResume { get; set; }

        /// <summary>
        /// Preserve stashes from completed builds, for use with stage restarting. For example: options { preserveStashes() }
        /// to preserve the stashes from the most recent completed build, or options { preserveStashes(buildCount: 5) } to preserve the stashes from the five most recent completed builds.
        /// </summary>
        public bool PreserveStashes { get; set; }

        public int? PreserveStashesBuildCount { get; set; }

        /// <summary>
        /// Set the quiet period, in seconds, for the Pipeline, overriding the global default.
        /// For example: options { quietPeriod(30) }
        /// </summary>
        public int? QuietPeriod { get; set; }

        /// <summary>
        /// On failure, retry the entire Pipeline the specified number of times.
        /// For example: options { retry(3) }
        /// </summary>
        public int? Retry { get; set; }

        /// <summary>
        /// Skip checking out code from source control by default in the agent directive.
        /// For example: options { skipDefaultCheckout() }
        /// </summary>
        public bool SkipDefaultCheckout { get; set; }

        /// <summary>
        /// Skip stages once the build status has gone to UNSTABLE
        /// . For example: options { skipStagesAfterUnstable() }
        /// </summary>
        public bool SkipStagesAfterUnstable { get; set; }

        /// <summary>
        /// Set a timeout period for the Pipeline run, after which Jenkins should abort the Pipeline.
        /// For example: options { timeout(time: 1, unit: 'HOURS') }
        /// </summary>
        public int? Timeout { get; set; }

        public string TimeoutUnit { get; set; }

        /// <summary>
        /// timestamps Prepend all console output generated by the Pipeline run with the time at which the line was emitted.
        /// For example: options { timestamps() }
        /// </summary>
        public bool TimeStamps { get; set; }

        /// <summary>
        /// Enables colored logs in jenkins console output. Jenkins ANSIColor plugin must be installed in jenkins.
        /// </summary>
        /// <returns></returns>
        public bool AnsiColors { get; set; }
    }
}
